package com.bsoft.gol.editor.controller;

import hcn.util.ResultCode;
import com.bsoft.gol.editor.utils.CommonUtils;

import hcn.util.BaseResponse;
import com.bsoft.gol.editor.editor.EditorQuestionnaireStyle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bsoft.gol.editor.service.EditorQuestionnaireStyleApi;


/**表单样式
 * @author zhangjie
 * @date 2019/6/20
 */
@RestController
@RequestMapping(value = "/api/auth/editorQuestionnaireStyle")
public class EditorQuestionnaireStyleController {

    @Autowired
    private EditorQuestionnaireStyleApi editorQuestionnaireStyleApi;

    /**
     * 表单外观新增
     * @param req
     * @return
     */
    @RequestMapping("/add")
    public BaseResponse<String> add(@RequestBody EditorQuestionnaireStyle req) {
        BaseResponse<String> response = new BaseResponse<>();
        if (CommonUtils.isNull(req.getQuestionnaireId())||CommonUtils.isNull(req.getDeviceType())) {
            response.setCode(ResultCode.PARAMETERS_EMPTY);
            response.setMessage("传入参数不能为空");
            return response;
        }

        String questionnaireStyleId = editorQuestionnaireStyleApi.addQuestionnaireStyle(req);
        response.setData(questionnaireStyleId);
        response.setMessage("保存成功");
        return response;
    }

    /**
     * 表单外观修改
     * @param req
     * @return
     */
    @RequestMapping("/update")
    public BaseResponse<String> update(@RequestBody EditorQuestionnaireStyle req) {
        BaseResponse<String> response = new BaseResponse<>();
        if (CommonUtils.isNull(req.getQuestionnaireStyleId())) {
            response.setCode(ResultCode.PARAMETERS_EMPTY);
            response.setMessage("传入参数不能为空");
            return response;
        }
        editorQuestionnaireStyleApi.updateQuestionnaireStyle(req);
        response.setMessage("保存成功");
        return response;
    }

    /**
     * 表单外观详情
     * @param req
     * @return
     */
    @RequestMapping("/detail")
    public BaseResponse<EditorQuestionnaireStyle> detail(@RequestBody EditorQuestionnaireStyle req) {
        BaseResponse<EditorQuestionnaireStyle> response = new BaseResponse<EditorQuestionnaireStyle>();
        if (CommonUtils.isNull(req.getQuestionnaireId())||CommonUtils.isNull(req.getDeviceType())) {
            response.setCode(ResultCode.PARAMETERS_EMPTY);
            response.setMessage("传入参数不能为空");
            return response;
        }
        EditorQuestionnaireStyle editorQuestionnaireStyle = editorQuestionnaireStyleApi.getQuestionnaireStyleById(req);
        response.setData(editorQuestionnaireStyle);
        response.setMessage("保存成功");
        return response;
    }

}
